package com.example.community.add;

import com.example.community.dao.ParkingDao;
import com.example.community.model.Parking;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/parkingAddServlet")
public class ParkingAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("/WEB-INF/parkingManager/parkingAdd.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            String pno = req.getParameter("pno");

            Parking parking = new Parking();
            parking.setpNo(Integer.parseInt(pno));
            ParkingDao parkingDao = new ParkingDao();
            Integer insert = parkingDao.insert(parking);
            if (insert == 1){
                resp.getWriter().write("true");
            }else {
                resp.getWriter().write("false");
            }
        }catch (Exception e){
            resp.getWriter().write("false");
        }

    }
}
